package com.xhj.myframe.myAQS;

import java.util.Random;
import java.util.concurrent.locks.ReentrantLock;
/** @author haijianxia pure_xhj@163.com @Date 2021-08-24 @Time 17:48 */
public class LockDebugDemo {
  public static void main(String[] args) {
    ReentrantLock lock = new ReentrantLock(false);

    new Thread(
            () -> {
              lock.lock();
              try {
                System.out.println(Thread.currentThread().getName() + " come in and todo...");
              } catch (Exception e) {
                e.printStackTrace();
              } finally {
                // 暂不解锁
                //				lock.unlock();
              }
            },
            "AAA")
        .start();
    new Thread(
            () -> {
              Random random = new Random();
              int nextInt = random.nextInt(1000);
              try {
                Thread.sleep(500);
              } catch (InterruptedException e) {
                e.printStackTrace();
              }
              // 等待进入队列
              lock.lock();
              try {
                System.out.println(Thread.currentThread().getName() + " come in and todo...");
              } catch (Exception e) {
                e.printStackTrace();
              } finally {
                lock.unlock();
              }
            },
            "BBB")
        .start();
    //		new Thread(()->{
    //			lock.lock();
    //			try{
    //				System.out.println(Thread.currentThread().getName()+" come in and todo...");
    //			}catch (Exception e) {e.printStackTrace();}finally{
    //				lock.unlock();}
    //		},"CCC").start();

  }
}
